package com.openspring.platform.controller;

import java.util.HashMap;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.openspring.framework.controller.GenericController;
import com.openspring.framework.util.ResultUtils;
import com.openspring.platform.model.Dictionary;
import com.openspring.platform.service.DictionaryService;

@Controller
@RequestMapping("/dictionary")
public class DictionaryController extends GenericController<Dictionary, Long> {
	
	private DictionaryService dictionaryService;

	@Resource(name="dictionaryService")
	public void setDictionaryService(DictionaryService dictionaryService) {
		this.dictionaryService = dictionaryService;
		super.setGenericService(dictionaryService);
	}
	
	@RequestMapping(value="/query", method=RequestMethod.GET)
	@ResponseBody
	public Map<String, Object> list(@RequestParam(value="code") String code) {
		return ResultUtils.datas(dictionaryService.findByDictCode(code));
	}
	
	@RequestMapping(value="/initDictionary", method=RequestMethod.GET)
	@ResponseBody
	public Map<String, Object> initDictionary() {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("success", true);
		map.put("datas", dictionaryService.findDictionarys());
		return map;
	}
}
